import java.util.ArrayList;

import org.jgap.FitnessFunction;
import org.jgap.IChromosome;

public class GTFitnessFunction extends FitnessFunction {
	private static final long serialVersionUID = -5893757242142029320L;
	
	@Override
	protected double evaluate(IChromosome chromosome) {
		String path = Main.PATH_GUNTACTYX;
		String fileName = "resultados_" + Main.getGeneration() + ".txt";
		Integer idRobot = Main.mappRobotChromosome.get(chromosome.hashCode());
		ArrayList<String> lineas = FileManager.ReadResultsFromFile(path, fileName);
		double value = 0.0;
		// Busco cual es el robot que estoy evaluando
		for (int i = 0; i < lineas.size(); i++)
		{
			if (lineas.get(i).split(" ")[1] == idRobot.toString())
			{
				value = Double.valueOf(lineas.get(i).split(" ")[3]).doubleValue();
				break;
			}
		}
		return value;
	}

	
}
